package com.isnotlocus.gulimail.product.controller;

import java.util.Arrays;
import java.util.Map;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.isnotlocus.gulimail.product.entity.SkuInfoEntity;
import com.isnotlocus.gulimail.product.service.SkuInfoService;
import com.isnotlocus.common.utils.PageUtils;
import com.isnotlocus.common.utils.R;



/**
 * sku信息
 *
 * @author IsnotLocus
 * @email sunlightcs@gmail.com
 * @date 2020-07-16 17:00:57
 */
@RestController
@RequestMapping("product/skuinfo/")
public class SkuInfoController {
    @Autowired
    private SkuInfoService skuInfoService;

    /**
     * 列表
     */
    @GetMapping("/list")
    //@RequiresPermissions("product:skuinfo:list")
    public R list(@RequestParam Map<String, Object> params){
       // PageUtils page = skuInfoService.queryPage(params);

        PageUtils pageUtils=skuInfoService.selectByMapBatch(params);

        return R.ok().put("page", pageUtils);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{skuId}")
   // @RequiresPermissions("product:skuinfo:info")
    public R info(@PathVariable("skuId") Long skuId){
		SkuInfoEntity skuInfo = skuInfoService.getById(skuId);

        return R.ok().put("skuInfo", skuInfo);
    }


    /**
     * openFeign 远程调用的接口
     * @param skuId
     * @return
     */
    @GetMapping("/info")
    // @RequiresPermissions("product:skuinfo:info")
    public R infoByWare(@RequestParam("skuId") Long skuId){
        SkuInfoEntity skuInfo = skuInfoService.getById(skuId);
        return R.ok().put("skuInfo", skuInfo);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("product:skuinfo:save")
    public R save(@RequestBody SkuInfoEntity skuInfo){
		skuInfoService.save(skuInfo);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
   // @RequiresPermissions("product:skuinfo:update")
    public R update(@RequestBody SkuInfoEntity skuInfo){
		skuInfoService.updateById(skuInfo);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("product:skuinfo:delete")
    public R delete(@RequestBody Long[] skuIds){
		skuInfoService.removeByIds(Arrays.asList(skuIds));
        return R.ok();
    }

    /**
     * 商品上架
     */
    @RequestMapping("/{skuId}/up")
    //@RequiresPermissions("product:skuinfo:delete")
    public R SkuUp(@PathVariable("skuId") Long skuId){
        skuInfoService.upSku(skuId);
        return R.ok();
    }

}
